<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px" class="demoTable">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">合同编号</label>
                            <div class="layui-input-inline">
                                <input name="rsbConNum" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">失效时间</label>
                            <div class="layui-inline">
                                <input type="text" id="date1" name="rsbConEnd1" class="layui-input test-item" placeholder="yyyy-MM-dd HH:mm:ss">
                            </div>
                            <div class="layui-inline">
                                <input type="text" id="date2" name="rsbConEnd2" class="layui-input test-item" placeholder="yyyy-MM-dd HH:mm:ss">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    id="searchs"   lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <a style="width: 10%" class="layui-btn layui-btn-fluid" href="/#/page/rsb/contract.html"> 添加 </a>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

        <!--点击人名到本人信息的详情页面-->
        <script type="text/html" id="img">
            <a href="/#/page/rsb/user.html?employName={{d.userName}}" style="color: #1e88e5">{{d.userName}}</a>
        </script>

    </div>
</div>
<script>
    layui.use(['form', 'table','laydate','miniPage','element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            miniPage = layui.miniPage;

        laydate.render({
            elem: '#date1'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#date2'
            ,type: 'datetime'
        });


        table.render({
            elem: '#currentTableId',
            url: '/showAllContract',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: '', width: 40, title: ''},
                {field: 'rsbConNum', width: 135, title: '合同编号'},
                {field: 'rsbConName', width: 135, title: '合同名称'},
                {field: 'userNum', width: 120, title: '员工'},
                {field: 'userName', width: 120, title: '员工姓名',templet: '#img' },
                {field: 'rsbConType', width: 120, title: '合同类别'},
                {field: 'rsbConNow', width: 135, title: '签约时间'},
                {field: 'rsbConBegin', width: 135, title: '生效时间'},
                {field: 'rsbConEnd', width: 135, title: '失效时间'},
                {field: 'rsbConBasepay', width: 100, title: '基本薪资'},
                {field: 'rsbConPath', width: 135, title: '附件上传路径'},
                {title: '操作', minWidth: 135, toolbar: '#currentTableBar', align: "center"}
            ]],
        });


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                where: {
                    condition: result
                },
                url:"/showSearchContract",
                method:"post"
            });
            return false;
        });




        //tool删除监听器
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                var num=data.rsbConNum;
                layer.confirm('真的删除员工编号'+num+'吗？',{btn:['是的,我确定','我再想想']}, function (index) {
                    $.ajax({
                        url:"/deleteContract",
                        dataType:'json',
                        data:{
                            rsbContractNum:num
                        }
                    })
                    obj.del();
                    layer.close(index);
                });
            }
        });

    });


    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();



        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });


        //表单初始赋值
        form.val('example', {
            "username": "贤心" // "name": "value"
            , "password": "123456"
            , "interest": 1
            , "like[write]": true //复选框选中状态
            , "close": true //开关状态
            , "sex": "女"
            , "desc": "我爱 layui"
        })
    });
</script>